import { createStore } from 'vuex'
import createPersistedState from 'vuex-persistedstate'
// 创建一个新的 store 实例
const store = createStore({
	state() {
		return {
			title: '患者管理',
			username: '',
			menuIndex: 0,
			roleId: '',
			hospitalName:'',
			hospitalSite:'',
			hospitalPhone:''
		}
	},
	mutations: {
		updateTitle(state: any, payload: any) {
			state.title = payload
		},
		updateUserName(state: any, payload: any) {
			state.username = payload
		},
		updateMenuIndex(state: any, payload: any) {
			state.menuIndex = payload
		},
		updateRoleId(state: any, payload: any) {
			// console.log('roleId',payload)
			state.roleId = payload
		},
		setHospitalMessage(state,payload){
			state.hospitalName=payload[0]
			state.hospitalSite=payload[1]
			state.hospitalPhone=payload[2]
		}
	},
	plugins: [
		createPersistedState({
			storage: window.sessionStorage
		})
	]
})
export default store